#!/bin/bash

#/bin/echo "creating /var/lock/ozy.lock" >> /var/log/ozy.log 2>&1
#/bin/echo `/bin/date` > /var/lock/ozy.lock

PATH=/usr/local/ozy:$PATH
RELEASE=/usr/local/ozy

USB_VID=0xfffe
USB_PID=0x0007
#USB_VID=$1
#USB_PID=$2

#OZY_HEX=ozyfw.hex
OZY_HEX=ozyfw-sdr1k.hex.save

/bin/echo "Loading Ozy hex file $OZY_HEX" >> /var/log/ozy.log
loadFW $USB_VID $USB_PID $RELEASE/$OZY_HEX
sleep 5

#JANUS_RBF=SpecAn.rbf
JANUS_RBF=Ozy_Janus.rbf.save

/bin/echo "Loading Janus FPGA file $JANUS_RBF" >> /var/log/ozy.log
loadFPGA $USB_VID $USB_PID $RELEASE/$JANUS_RBF
#sleep 5

#        1E 00 - Reset chip
#        12 01 - set digital interface active
#        08 15 - D/A on, mic input, mic 20dB boost
#        08 14 - ditto but no mic boost
#        0C 00 - All chip power on
#        0E 02 - Slave, 16 bit, I2S
#        10 00 - 48k, Normal mode
#        0A 00 - turn D/A mute off
write_i2c $USB_VID $USB_PID 0x1a 0x1e 0x00 0x00 2
write_i2c $USB_VID $USB_PID 0x1a 0x12 0x01 0x00 2
write_i2c $USB_VID $USB_PID 0x1a 0x08 0x15 0x00 2
write_i2c $USB_VID $USB_PID 0x1a 0x0c 0x00 0x00 2
write_i2c $USB_VID $USB_PID 0x1a 0x0e 0x02 0x00 2
write_i2c $USB_VID $USB_PID 0x1a 0x10 0x00 0x00 2
write_i2c $USB_VID $USB_PID 0x1a 0x0a 0x00 0x00 2

write_i2c $USB_VID $USB_PID 0x1b 0x1e 0x00 0x00 2
write_i2c $USB_VID $USB_PID 0x1b 0x12 0x01 0x00 2
write_i2c $USB_VID $USB_PID 0x1b 0x08 0x15 0x00 2
write_i2c $USB_VID $USB_PID 0x1b 0x0c 0x00 0x00 2
write_i2c $USB_VID $USB_PID 0x1b 0x0e 0x02 0x00 2
write_i2c $USB_VID $USB_PID 0x1b 0x10 0x00 0x00 2
write_i2c $USB_VID $USB_PID 0x1b 0x0a 0x00 0x00 2

##/bin/rm -f /var/lock/ozy.lock
##/bin/echo "removed /var/lock/ozy.lock" >> /var/log/ozy.log 2>&1

exit 0
